package com.becca.cake.model.goods;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import org.springframework.web.multipart.MultipartFile;

import com.becca.cake.core.exception.ServiceException;

/**
 * 商品图片表
 * @copyright  尊星(上海)信息科技有限公司
 * @author hejinguo
 * @date 2016年4月10日 上午2:21:37
 */
public class GoodsPictureModel implements Serializable {
    /**  */
    private static final long serialVersionUID = -8596829458089693919L;

    private Integer           id;
    /**商品ID*/
    private Integer           goodsId;
    /**图片名称*/
    private String            picName;
    /**图片路径*/
    private String            picPath;
    /**图片排序*/
    private Integer           picOrder;
    /**是否删除(0:否 1:是)*/
    private Byte              isDelete;
    /**创建时间*/
    private Date              createdDate;
    /**创建人*/
    private String            createdName;
    /**商品名称*/
    private String 			  goodsName;
    /**适用来源(0:通用 1:微信 2:web)*/
    private Byte              applySource;
    
    /**图片未删除*/
    public static final Byte PIC_IS_NOT_DELETE = 0;

    /**图片已删除*/
    public static final Byte PIC_IS_DELETE = 1;
    
    
    /**上传的图片不存在*/
    public static final String PICTURE_NULL = "上传的图片不存在";
    
    /**图片上传失败*/
    public static final String PICTURE_UPDLOAD_FAILED = "图片上传失败";
    
    /**未填写图片名*/
    public static final String PICTURE_NAME_NULL = "未填写图片名";
    
    /**商品图片对象为空*/
    public static final String GOODS_PICTURE_NULL = "商品图片对象为空";
    
    /**商品图片ID为空*/
    public static final String GOODS_PICTURE_ID_NULL = "商品图片ID为空";
    
    /**该商品图片图片信息已被删除*/
    public static final String GOODS_PICTURE_DELETE = "该商品图片图片信息已被删除";
    
    /**图片排序不能为空*/
    public static final String GOODS_PICTURE_ORDER_NULL = "图片排序不能为空";
    
    /**
     * 添加、修改商品图片校验
     * @param goodsPictureModel
     * @param files
     */
    public static void validAddOrUpdGoodsPic(GoodsPictureModel goodsPictureModel, MultipartFile files){
        if(goodsPictureModel == null){
            throw new ServiceException(GoodsPictureModel.GOODS_PICTURE_NULL);
        }
        if(goodsPictureModel.getId() == null && files.isEmpty() ){
            throw new ServiceException(GoodsPictureModel.PICTURE_NULL);
        }
        if(goodsPictureModel.getPicName() == null || goodsPictureModel.getPicName() == ""){
            throw new ServiceException(GoodsPictureModel.PICTURE_NAME_NULL);
        }
    }
    
    /**
     * 校验商品图片ID是否为空
     * @param id
     */
    public static void validGoodsPictureIsNull(Integer id){
        if(id == null){
            throw new ServiceException(GoodsPictureModel.GOODS_PICTURE_ID_NULL);
        }
    }
    
    /**
     * 校验商品图片排序
     * @param list
     */
    public static void validGoodsPicOrders(List<GoodsPictureModel> list){
        for (GoodsPictureModel goodsPictureModel : list) {
            if(goodsPictureModel.getPicOrder() == null){
                throw new ServiceException(GoodsPictureModel.GOODS_PICTURE_ORDER_NULL);
            }
        }
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getGoodsId() {
        return goodsId;
    }

    public void setGoodsId(Integer goodsId) {
        this.goodsId = goodsId;
    }

    public String getGoodsName() {
        return goodsName;
    }

    public void setGoodsName(String goodsName) {
        this.goodsName = goodsName;
    }

    public String getPicName() {
        return picName;
    }

    public void setPicName(String picName) {
        this.picName = picName;
    }

    public String getPicPath() {
        return picPath;
    }

    public void setPicPath(String picPath) {
        this.picPath = picPath;
    }

    public Integer getPicOrder() {
        return picOrder;
    }

    public void setPicOrder(Integer picOrder) {
        this.picOrder = picOrder;
    }

    public Byte getIsDelete() {
        return isDelete;
    }

    public void setIsDelete(Byte isDelete) {
        this.isDelete = isDelete;
    }

    public Date getCreatedDate() {
        return createdDate;
    }

    public void setCreatedDate(Date createdDate) {
        this.createdDate = createdDate;
    }

    public String getCreatedName() {
        return createdName;
    }

    public void setCreatedName(String createdName) {
        this.createdName = createdName;
    }

    public Byte getApplySource()
	{
		return applySource;
	}

	public void setApplySource(Byte applySource)
	{
		this.applySource = applySource;
	}

	@Override
    public String toString() {
        return "GoodsPictureDO [id=" + id + ", goodsId=" + goodsId + ", picName=" + picName
               + ", picPath=" + picPath + ", picOrder=" + picOrder + ", isDelete=" + isDelete
               + ", createdDate=" + createdDate + ", createdName=" + createdName + "]";
    }

}
